_realname=yubikey-personalization
_shortname=ykpers
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.20.0
pkgrel=1
pkgdesc="Yubico YubiKey Personalization library and tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/Yubico/yubikey-personalization'
license=('BSD')
depends=(
  "${MINGW_PACKAGE_PREFIX}-libusb"
  "${MINGW_PACKAGE_PREFIX}-json-c"
  "${MINGW_PACKAGE_PREFIX}-yubico-c"
)
validpgpkeys=('0A3B0262BCA1705307D5FF06BCA00FD4B2168C0A') # Klas Lindfors <klas@yubico.com>
source=("https://developers.yubico.com/${_realname}/Releases/${_shortname}-${pkgver}.tar.gz"{,.sig}
        '0001-fix-boolean-value-with-json-c-0.14.patch')
sha256sums=('0ec84d0ea862f45a7d85a1a3afe5e60b8da42df211bb7d27a50f486e31a79b93'
            'SKIP'
            'f9b434e9570ce7d0192182aab979f767238b704f12645546e567db841bb7b5e2')

prepare() {
  cd ${srcdir}/${_shortname}-${pkgver}

  patch -p1 -i ${srcdir}/0001-fix-boolean-value-with-json-c-0.14.patch

  autoreconf -vfi
}

build() {
  cd "${srcdir}"/${_shortname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  export lt_cv_deplibs_check_method='pass_all'
  CFLAGS+=" -fcommon"

  ../${_shortname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}

  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}

  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_shortname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
